﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OpticalPowerMeter
{
    /// <summary>
    /// 波长类
    /// </summary>
    public class MyWavelength:IComparable
    {
        /// <summary>
        /// 无参构造器
        /// </summary>
        public MyWavelength() { }

        /// <summary>
        /// 带有两个参数的构造器
        /// </summary>
        /// <param name="wavelength">波长</param>
        /// <param name="mode">波长类型</param>
        public MyWavelength(int wavelength,WavelengthMode mode)
        {
            Wavelength = wavelength;
            Mode = mode;
        }
        /// <summary>
        /// 波长
        /// </summary>
        public int Wavelength { set; get; }
        /// <summary>
        /// 模式 单模或多模
        /// </summary>
        public WavelengthMode Mode { set; get; }

        /// <summary>
        /// 重载运算"<"运算符,对比两个对象的wavelength
        /// </summary>
        /// <param name="paramA">MyWavelength</param>
        /// <param name="paramB">MyWavelength</param>
        /// <returns>第一个是不是小于第二个MyWavelength</returns>
        public static bool operator <(MyWavelength paramA, MyWavelength paramB)
        {
            return paramA.Wavelength < paramB.Wavelength;
        }

        /// <summary>
        /// 重载运算">"运算符,对比两个对象的wavelength
        /// </summary>
        /// <param name="paramA">MyWavelength</param>
        /// <param name="paramB">MyWavelength</param>
        /// <returns>第一个是不是大于第二个MyWavelength</returns>
        public static bool operator >(MyWavelength paramA, MyWavelength paramB)
        {
            return paramA.Wavelength > paramB.Wavelength;
        }

        /// <summary>
        /// 重载运算符"=="，对比两个对象的wavelength,注意这里结果与Equals结果会不一样，Equals会比对wavelength及mode
        /// </summary>
        /// <param name="paramA">MyWavelength</param>
        /// <param name="paramB">MyWavelength</param>
        /// <returns>两个对象的Wavelength是否一致</returns>
        public static bool operator ==(MyWavelength paramA, MyWavelength paramB)
        {
            return paramA.Wavelength == paramB.Wavelength;
        }

        /// <summary>
        /// 重载运算符"!="，对比两个对象的wavelength,注意这里结果与Equals结果会不一样，Equals会比对wavelength及mode
        /// </summary>
        /// <param name="paramA">MyWavelength</param>
        /// <param name="paramB">MyWavelength</param>
        /// <returns>两个对象的Wavelength是否一致</returns>
        public static bool operator !=(MyWavelength paramA, MyWavelength paramB)
        {
            return paramA.Wavelength != paramB.Wavelength;
        }

        /// <summary>
        /// 重写父类的Equals，比对对象的两个属性值是否一致
        /// </summary>
        /// <param name="obj">参与比对的对象</param>
        /// <returns>是否一致</returns>
        public override bool Equals(object obj)
        {
            if (obj.GetType().Name.EndsWith("MyWavelength"))
            {
                return Equals(obj as MyWavelength);
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 重写Equals，比对对象的两个属性值是否一致
        /// </summary>
        /// <param name="obj">参与比对的对象</param>
        /// <returns>是否一致</returns>
        public bool Equals(MyWavelength other)
        {
            if (other == null)
            {
                return false;
            }
            return other.Wavelength == Wavelength && other.Mode == Mode;
        }

        /// <summary>
        /// 重写获取Hash表的方式
        /// </summary>
        /// <returns>MyWavelength对象的Hash表</returns>
        public override int GetHashCode()
        {
            return (Wavelength, Mode).GetHashCode();
        }

        public int CompareTo(object obj)
        {
            if (!obj.GetType().Name.EndsWith("MyWavelength"))
            {
                throw new NotImplementedException();
            }
            MyWavelength myWavelength = obj as MyWavelength;
            return Wavelength.CompareTo(myWavelength.Wavelength);
        }
    }
}
